;	Copyright (C) 2009 Salil Bhagurkar
;	
;	This file is part of ViSE
;	
;	ViSE is free software: you can redistribute it and/or modify
;	it under the terms of the GNU Lesser General Public License as published by
;	the Free Software Foundation, either version 3 of the License, or
;	(at your option) any later version.
;	
;	ViSE is distributed in the hope that it will be useful,
;	but WITHOUT ANY WARRANTY; without even the implied warranty of
;	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;	GNU Lesser General Public License for more details.
;	
;	You should have received a copy of the GNU Lesser General Public License
;	along with ViSE.  If not, see <http://www.gnu.org/licenses/>.

[bits 32]

global __setgdt
__setgdt:
enter 0,0
pusha
	lgdt [gdt_desc]
	jmp SYS_CODE_SEL:flush_ipq
	flush_ipq:
	mov ax,SYS_DATA_SEL
	mov ds,ax 
	mov es,ax
	mov fs,ax
	mov gs,ax
	mov ss,ax 
popa
leave
ret

global __reload_gdt
__reload_gdt:
	lgdt [gdt_desc]
ret

gdt:

gdt_null:
        dd 0
        dd 0

SYS_CODE_SEL	equ	$-gdt
gdt_code:
        dw 0FFFFh
        dw 0
        db 0
        db 0x9A
        db 0xCF
        db 0

SYS_DATA_SEL	equ	$-gdt
gdt_data:
        dw 0FFFFh
        dw 0
        db 0
        db 0x92
        db 0xCF
        db 0

REAL_CODE_SEL	equ	$-gdt
gdt3:	dw 0xFFFF
	dw 0
	db 0
	db 0x9A
	db 0
	db 0
	
REAL_DATA_SEL	equ	$-gdt
gdt4:	dw 0xFFFF
	dw 0x100
	db 0
	db 0x92
	db 0
	db 0
       
gdt_end:


gdt_desc: 
        dw gdt_end - gdt - 1
        dd gdt
